package com.wms_backend.controller;

import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.interfaces.Claim;
import com.wms_backend.entity.Result;
import com.wms_backend.security.UserDetailsImpl;
import com.wms_backend.service.InboundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.wms_backend.utils.JwtUtil.verifyToken;

@RestController
@RequestMapping("/inbound")
public class InboundController {

    @Autowired
    InboundService inboundService;

    @PostMapping("/create")
    public Result create(@RequestBody JSONObject param) {

        UserDetailsImpl principal = (UserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String userId = principal.getUserId();
        return inboundService.create(param, userId);
    }

    @PostMapping("/check")
    public Result check(@RequestBody JSONObject param) {
        UserDetailsImpl principal = (UserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String userId = principal.getUserId();
        return inboundService.check(param, userId);
    }

    @PostMapping("/query-order")
    public Result query(@RequestBody JSONObject param, @RequestHeader String token) {
        UserDetailsImpl principal = (UserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String userId = principal.getUserId();
        return inboundService.queryByCondition(param, userId);
    }

    @PostMapping("/query-location")
    public Result queryLocation(@RequestBody JSONObject param, @RequestHeader String token){
        UserDetailsImpl principal = (UserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String userId = principal.getUserId();
        return inboundService.queryLocation(param,userId);
    }
}
